package com.zx.dsptuneup_TriMic.widget.tab;

import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zx.dsptuneup_TriMic.Base.BaseActivity;
import com.zx.dsptuneup_TriMic.R;

public class TitleTabBar {

    private BaseActivity activity;

    public ImageView iv_back;//返回

    private ImageView iv_right;//右侧按钮


    private TextView tv_right;//右侧文字

    private RelativeLayout rl_title_bar;

    private LinearLayout tabMode;

    public TitleTabBar(BaseActivity activity) {
        this.activity = activity;
        iv_back = activity.findViewById(R.id.iv_back);
        iv_right = activity.findViewById(R.id.iv_right);
        tv_right = activity.findViewById(R.id.tv_right);
        tabMode = activity.findViewById(R.id.tabMode);
        rl_title_bar = activity.findViewById(R.id.rl_title_bar);
    }

    public TitleTabBar(BaseActivity activity, View rootView) {
        this.activity = activity;
        iv_back = rootView.findViewById(R.id.iv_back);
        iv_right = rootView.findViewById(R.id.iv_right);
        tv_right = rootView.findViewById(R.id.tv_right);
    }

    public TitleTabBar showRight(String text, View.OnClickListener listener) {
        tv_right.setVisibility(View.VISIBLE);
        tv_right.setText(text);
        tv_right.setOnClickListener(listener);
        return this;
    }

    public TitleTabBar showRight(String text, int resId, View.OnClickListener listener) {
        tv_right.setVisibility(View.VISIBLE);
        tv_right.setText(text);
        tv_right.setOnClickListener(listener);
        Drawable drawable = activity.getResources().getDrawable(resId);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tv_right.setCompoundDrawables(null, null, drawable, null);
        return this;
    }

    public TitleTabBar showImg(int resId, View.OnClickListener listener) {
        iv_right.setVisibility(View.VISIBLE);
        iv_right.setOnClickListener(listener);
        iv_right.setImageResource(resId);
        return this;
    }

    public TitleTabBar back() {
        iv_back.setVisibility(View.VISIBLE);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                backDoing();
            }
        });
        return this;
    }

    public TitleTabBar hideBack() {
        iv_back.setVisibility(View.GONE);
        return this;
    }

    public TitleTabBar normal() {
        tabMode.setVisibility(View.VISIBLE);
        return this;
    }

    public TitleTabBar hideRight() {
        tv_right.setVisibility(View.GONE);
        return this;
    }

    public TitleTabBar setBgColor(String color) {
        rl_title_bar.setBackgroundColor(Color.parseColor(color));
        return this;
    }

    public TitleTabBar setBg(int backgroundResourse) {
        rl_title_bar.setBackgroundResource(backgroundResourse);
        return this;
    }

    public void backDoing() {
        activity.finish();
    }
}
